package com.example.demo.service;


import com.example.demo.constants.Constants;
import com.example.demo.mapper.UserInfoMapper;
import com.example.demo.modal.UserInfo;
import jakarta.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
public class UserService {
    @Autowired
    private UserInfoMapper userInfoMapper;
    public Boolean checkNameAndPassword(String userName, String password, HttpSession session){
        if(!StringUtils.hasLength(userName) || !StringUtils.hasLength(password)){
            return false;
        }
        UserInfo userInfo = userInfoMapper.selectUser(userName);
        if(userInfo == null){
            return false;
        }
        if(password.equals(userInfo.getPassword())){
            session.setAttribute(Constants.SESSION_USER_KEY,userName);
            return true;
        }
        return false;
    }
}
